<!DOCTYPE html>
<!-- 批发后台页面 -->
<html>
<head>
  <meta charset="utf-8">
<!--批发后台页面 -->
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
 
  <link rel="stylesheet" href="../../res/css/wholesale/font.css">
  <link rel="stylesheet" href="../../res/css/wholesale/xadmin.css">
  <link rel="stylesheet" href="../../res/layui/css/layui.css">
  <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  <script type="text/javascript" src="../../res/layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript" src="../../res/js/wholesale/xadmin.js"></script>
</head>
<body>
<!-- 刷新 <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">批发记录</a>
        <a>
          <cite>修改订单</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div> -->
<div class="demoTable" style="margin-top: 10px;">
 
    <div class="x-body">
      <div class="layui-row">
        <div class="layui-form layui-col-md12 x-so">
          <input type="text" name="id" id="demoReload" placeholder="请输入公司名" autocomplete="off" class="layui-input">
           <input type="text" name="bwTime" id="bwTime"   placeholder="批发开始时间" autocomplete="off" class="layui-input" readonly="readonly"> ——
          <input type="text" name="bwTime2" id="bwTime2"   placeholder="批发结束时间" autocomplete="off" class="layui-input" readonly="readonly"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
          <button class="layui-btn" data-type="reload" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </div>
      </div>
      <xblock>
        <button class="layui-btn" id="insert"><i class="layui-icon"></i>添加</button>
      </xblock>
<table class="layui-table" lay-data="{url:'../../listenBranchWholesale/selectNameAll.action', page:true, id:'idTest'}" lay-filter="demo">
  <thead>
    <tr>
      <th lay-data="{field:'bwId', sort: true, align:'center',style='display:none'}">批发ID</th>
      <th lay-data="{field:'companyName', align:'center',width:'10%'}">公司名称</th>
      <th lay-data="{field:'bwTimeString',align:'center',width:'10%'}">批发时间</th>
      <th lay-data="{field:'bwPrice', align:'center',width:'10%'}">销售总金额</th>
      <th lay-data="{field:'bwNumber', align:'center',width:'10%'}">销售总数量</th>
      <th lay-data="{field:'openTimeString', align:'center',width:'10%'}">操作时间</th>
      <th lay-data="{field:'oper', align:'center',width:'10%'}">操作人</th>
      <th lay-data="{field:'xt', align:'center',templet:'#audit',width:'10%'}">审核状态</th>
      <th lay-data="{field: 'right', align:'center', toolbar: '#barDemo',width:'20%'}">操作</th>
    </tr>
  </thead>
</table>
 </div>
 </div>
 <!-- 弹出层 -->
 <div id="addOrUpdate" style="display: none;">
	<table class="layui-table"  lay-filter="demo"id="zxc" >
		<thead>
			<tr>
			<!-- 	<th lay-data="{type:'checkbox', fixed: 'left'}"></th> -->
				<th lay-data="{align:'center',width:'8%'}">公司名称</th>
				<th lay-data="{align:'center',width:'8%'}">乐器类型</th>
				<th lay-data="{align:'center',width:'8%'}">乐器名称</th>
				<th lay-data="{align:'center',width:'8%'}">规格</th>
				<th lay-data="{align:'center',width:'8%'}">建议零售价（￥）</th>
				<th lay-data="{align:'center',width:'5%'}">批发数量</th>
				<th lay-data="{align:'center',width:'5%'}">小计（￥） </th>
				<th lay-data="{align:'center',width:'5%'}">批发价（￥）</th>
				<th lay-data="{align:'center',width:'6%'}">操作</th>
			</tr>
		</thead>
	</table>
	<div id="pfhj">
	<p><a id="hj">合计：</a><font id=hjjg>0</font>￥</p>
	</div>
	<div id="hjsl">
	<p><a id="sl">总数量：</a><font id=hjsls>0</font>个</p>
	</div>
	<div id="pftjs">
	     <button class="layui-btn" id="tjs" onclick="zxctj()" style="display:none">提交</button>
	 </div>
	<div class="demoTable2" style="margin-left: 20px; margin-top: 20px; display:inline" >
			搜索：
			<div class="layui-inline">
				<input class="layui-input" id="musical" style="height: 34px;" placeholder="请输入乐器名称" autocomplete="off">
			</div>
			
			<div class="layui-inline">
				<input class="layui-input" type="number" style="height: 34px;" id="price" placeholder="￥" autocomplete="off" style="width: 100px;"/>
			</div>
			-
			<div class="layui-inline">
				<input class="layui-input" type="number" style="height: 34px;" id="price2" placeholder="￥" autocomplete="off" style="width: 100px;"/>
			</div>
			
			<from class="layui-form" >
				<!-- <div class="layui-inline">
					<select lay-filter="aihao" data-type="reload" id="snacksType" style="height: 34px;width: 60px;">
						<option value="">====选择分公司====</option>
					</select>
				</div> -->
				<button class="layui-btn" data-type="reload2" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
			</from>
		</div>
		<table class="layui-table" lay-filter="insCom" id="idTest2">
			<!-- <thead>
				<tr>
					<th lay-data="{type:'checkbox', fixed: 'left'}"></th>
					<th lay-data="{field:'stockId', sort: true, align:'center'}">库存ID</th>
					<th lay-data="{field:'companyName', align:'center',width:'10%'}">公司名称</th>
					<th lay-data="{field:'mtName', align:'center',width:'8%'}">乐器类型</th>
					<th lay-data="{field:'muName', align:'center',width:'10%'}">乐器名称</th>
					<th lay-data="{field:'muPic', align:'center', sort: true,toolbar: '#Image',width:'8%'}">乐器图片</th>
					<th lay-data="{field:'muPrice', align:'center',width:'6%'}">乐器价格</th>
					<th lay-data="{field:'stockNumber', align:'center',width:'7%'}">库存数量</th>
					<th lay-data="{field:'muSpecifications', align:'center',width:'10%'}">乐器规格</th>
				</tr>
			</thead> -->
		</table>
</div>
<script type="text/javascript">
layui.use('laydate',function(){
	  var laydate = layui.laydate;
	  //执行一个laydate实例
	  laydate.render({
		  elem:'#bwTime'
	  	,theme: 'molv'
	  });
	  laydate.render({
		  elem:'#bwTime2'
	  	,theme: 'molv'
	  });

	});
	layui.use('table',function(){
		var table = layui.table;
		var form = layui.form;
		//默认一面后执行
		 
			  table.render({
				    elem: '#idTest2'
				    	,page: true
				    ,url:'../../listenStock/selectName.action'
				    ,cols: [[
				       {type:'checkbox'}
						,{field:'stockId', sort: true, align:'center',sort:true,title:'库存ID'}
						,{field:'companyName', align:'center',width:'10%',sort:true,title:'公司名称'}
						,{field:'mtName', align:'center',width:'8%',sort:true,title:'乐器类型'}
						,{field:'muName', align:'center',width:'10%',sort:true,title:'乐器名称'}
					 	,{field:'muPic', align:'center', sort: true,toolbar: '#Image',width:'8%',sort:true,title:'乐器图片'}
						,{field:'wholesale', align:'center',width:'6%',sort:true,title:'乐器价格'}
						,{field:'stockNumber', align:'center',width:'7%',sort:true,title:'库存数量'}
						,{field:'muSpecifications', align:'center',width:'10%',sort:true,title:'乐器规格'}
				    ]],done: function (res, curr, count) {
			            $("[data-field='stockId']").css('display','none');
				    }
				  });
		 
	})

</script>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="whodate">查看明细</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit">审核详情</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/javascript" id="audit">
{{# if(d.bwStatus == 1) { }}
<a class="layui-btn layui-btn-xs layui-btn-warm">等待财务审核</a>
{{# }else if(d.bwStatus == 2) { }}
<a class="layui-btn layui-btn-xs layui-btn-normal">等待总经理审核</a>
{{# }else if(d.bwStatus == 3) { }}
<a class="layui-btn layui-btn-xs layui-btn-normal">已审核</a>
{{# } else if(d.bwStatus == 4){ }}
	<a class="layui-btn layui-btn-xs layui-btn-danger">审核未通过</a>
{{# }}}
</script>
<script type="textml" id="imgTpl">
    		<img style="width:300px;height:50px;" onmouseover="getPathOver(this)" alt="暂无图片" onmouseout="getPathOut()" src="../../{{ d.userPicture }}">
		</script>
<script type="textml" id="Image">
    		<img style="width:300px;height:50px;" onmouseover="getPathOver(this)" alt="暂无图片" onmouseout="getPathOut()" src="../../{{ d.muPic }}">
		</script>

<script type="text/javascript" src="../../res/js/wholesale/wholesale.js"></script>
<script type="text/javascript">
//计算批发值
function parName(obj,num){
	
	
	 obj.value = obj.value.replace(/[^\d]/g,"");//清除“数字”和“.”以外的字符  
	    if(obj.value.indexOf(".")< 0 && obj.value !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额 
	        obj.value= parseFloat(obj.value);
	    }
	    if(obj.value.indexOf(".")==0){//第一个字符不能为.
	    	 obj.value="0";
	    }
	
	var s=0;
	var h=0;
	  var a=obj.value;
	  if(a!=0 && a!=""){
	  var hjjg=$("#hjjg");
	  var hjsls=$("#hjsls");
	  if(a>num){
		  layer.msg("库存不足",{time:1000});
		  obj.value="0";
		  var b=$(obj).parent().prev().text();
	 		 
		  var c =parseFloat($(obj).val())*parseFloat(b);
		  $(obj).parent().next().children().val(c);
		  $(obj).parent().next().next().children().val(c);
		$("#hjjg").text(0);
     	$("#hjsls").text(0);
     	$("#zxc").find("tr").each(function(i,item){
     		var number=$(item).find("td").get(5)
     		var price=$(item).find("td").get(7)
     		var prices=$(price).children().val();
     		var numbers=$(number).children().val()
     		
     		if(numbers!=undefined && prices!=undefined){
     			console.info("aaaaaaa"+prices)
     			
     			$("#hjjg").html(parseFloat($("#hjjg").html())+parseFloat(prices))
         		$("#hjsls").html(parseInt($("#hjsls").html())+parseInt(numbers))
         		 
     		}
     	})
		  
	  }else{
		  console.info("aaaa")
		  /* if(a<10){ */
			  console.info("skjsksk")
			  var b=$(obj).parent().prev().text();
			  var c =parseFloat($(obj).val())*parseFloat(b);
			  $(obj).parent().next().children().val(c);
			  $(obj).parent().next().next().children().val(c);
			  $("#zxc tr").not(":first").each(function(){
					s+=parseInt($(this).find('td:eq(5) input').val());
					h+=parseFloat($(this).find('td:eq(7) input').val());
			  })
				console.info(h)
				console.info(s)
				 hjjg.html(h);
			 	 hjsls.html(s);
		 /*  }else{
			  var b=$(obj).parent().prev().text();
			  var d =parseFloat($(obj).val())*parseFloat(b);
			  var c =(parseFloat($(obj).val())*parseFloat(b))*0.8;
			  $(obj).parent().next().children().val(d);
			  $(obj).parent().next().next().children().val(c);
			  $("#zxc tr").not(":first").each(function(){
				 
					s+=parseInt($(this).find('td:eq(5) input').val());
					h+=parseInt($(this).find('td:eq(7) input').val());
				})
				hjjg.html(h);
			  	hjsls.html(s);
		   }*/
		 
	  }
	  }else{
		  console.info("bbbbb")
		 layer.msg("库存不能为空",{time:2000});
		 if(obj.value ==0){
		    	obj.value = '0';
		    }
		 var b=$(obj).parent().prev().text();
 		 
		  var c =parseFloat($(obj).val())*parseFloat(b);
		  $(obj).parent().next().children().val(c);
		  $(obj).parent().next().next().children().val(c);
		$("#hjjg").text(0);
     	$("#hjsls").text(0);
     	$("#zxc").find("tr").each(function(i,item){
     		var number=$(item).find("td").get(5)
     		var price=$(item).find("td").get(7)
     		var prices=$(price).children().val();
     		var numbers=$(number).children().val()
     		
     		if(numbers!=undefined && prices!=undefined){
     			console.info("aaaaaaa"+prices)
     			
     			$("#hjjg").html(parseFloat($("#hjjg").html())+parseFloat(prices))
         		$("#hjsls").html(parseInt($("#hjsls").html())+parseInt(numbers))
         		 
     		}/* else{
     			console.info(prices+"="+$("#hjjg").html()+"    "+numbers)
         		  var b=$(obj).parent().prev().text();
         		 
				  var c =parseFloat($(obj).val())*parseFloat(b);
				  $(obj).parent().next().children().val(c);
				  $(obj).parent().next().next().children().val(c);
     			$("#hjjg").text(parseFloat($("#hjjg").html())+parseFloat(prices))
         		$("#hjsls").text(parseInt($("#hjsls").html())+parseInt($(obj).val()))
     		} */
     		
     	})
	  }
	 
	}
	//提交进入批发action的方法
	function zxctj(){
		var html="";
		var kccw="";
		$("#zxc tr").not(":first").each(function(){
			$(this).find("td").each(function(j){
				html+=$(this).text()+",";
			})
			
			if($(this).find('td:eq(5) input').val()!=0 && $(this).find('td:eq(5) input').val()!=null){
			html+=$(this).find('td:eq(6) input').val()+",";
			html+=$(this).find('td:eq(7) input').val()+",";
			html+=$(this).find('td:eq(8) input').val()+",";
			html+=$(this).find('td:eq(9) input').val()+",";
			html+=$(this).find('td:eq(10) input').val()+",";
			html+=$(this).find('td:eq(5) input').val()+"#";
			}else{
				/* layer.msg("库存数量输入错误",{time:2000}); */
				 kccw="kcsl";
			}
		})
		
		/* alert(html) */
		var hjjg=$("#hjjg").html();
		var hjsls=$("#hjsls").html();
		if(kccw=="kcsl"){
			layer.msg("库存数量输入错误",{time:2000});
		}else{
			//加载层
			var index = layer.load(0, {
				  shade: [0.1,'#fff'] //0.1透明度的白色背景
				});
		//判断提交的值
		var url="../../listenBranchWholesale/addWhole.action";
		var data={"html":html,"hjjg":hjjg,"hjsls":hjsls};
		$.post(url,data,function(mes){
			/* alert(mes.datas) */
			if(mes.datas==1){
			
				layer.msg(mes.msg,function(){
					
					icon:2;
					});
					/* parent.location.href="../../pages/wholesales/wholesalel.html"; */
					location.reload(); //刷新本页面
			}else{
				layer.msg(mes.msg,function(){
					icon:2;
					});
				  	location.reload();
			}
			/* alert("dsd") */
			
		},"json")
		}
	}
	
	
	
	//点击删除
	 function deletes(obj,id){
		  
		 $(obj).closest('tr').remove();
	/* 	 alert(id) */
		 
		//根据删除去掉复选框
		$('.layui-table-view').find('.layui-table tr').each(function(index,item){
			var ids=$(item).find('td[data-field="stockId"]').text();
		
				if(ids==id){
					var index=$(item).data('index');
		            var che = $("#idTest2").next().find('.layui-table tr[data-index="'+index+'"] input[name="layTableCheckbox"]')
		            console.info(che)
		            che.prop("checked",false)
		            load();
				}

		})
		 
		 
		 //根据文本框的值判断总价格，总数量
		 $("#hjjg").text(0);
     	$("#hjsls").text(0);
     	$("#zxc").find("tr").each(function(i,item){
     		var number=$(item).find("td").get(5)
     		var price=$(item).find("td").get(7)
     		var prices=$(price).children().val();
     		var numbers=$(number).children().val()
     		
     		if(numbers!=undefined && prices!=undefined){
     			console.info(prices)
         		console.info(numbers)
         		console.info($("#hjjg").html())
         		console.info($("#hjsls").html())
     			$("#hjjg").text(parseFloat($("#hjjg").html())+parseFloat(prices))
         		$("#hjsls").text(parseInt($("#hjsls").html())+parseInt(numbers))
         		 
     		}
     		
     	})
		}
	 
	 function load(){
			var form = layui.form;
			form.render();
		}

</script>
</body>
</html>